import request from '@/utils/request';
import { DeviceQuery, DeviceVO, DeviceForm } from './types';
import { AxiosPromise } from 'axios';

// 查询设备列表
export const getDeviceList = (query: DeviceQuery): AxiosPromise<DeviceVO[]> => {
  return request({
    url: '/vending/base/list',
    method: 'get',
    params: query
  });
};

// 查询设备详细
export const getDeviceDetail = (id: number, type: number): AxiosPromise<DeviceVO> => {
  return request({
    url: '/vending/base/' + id + '/' + type,
    method: 'get'
  });
};

// 新增设备
export const createDevice = (data: DeviceForm): AxiosPromise<DeviceVO> => {
  return request({
    url: '/vending/base',
    method: 'post',
    data: data
  });
};

// 修改设备
export const updateDevice = (data: DeviceForm): AxiosPromise<DeviceVO> => {
  return request({
    url: '/vending/base',
    method: 'put',
    data: data
  });
};

// 删除设备
export const deleteDevice = (id: number | Array<number>) => {
  return request({
    url: '/vending/base/' + id,
    method: 'delete'
  });
};

// 导出设备
export const exportDevice = (query: DeviceQuery) => {
  return request({
    url: '/vending/base/export',
    method: 'get',
    params: query,
    responseType: 'blob'
  });
};

//设备总数添加
export const updateCount = (id: number, count: number) => {
  return request({
    url: '/vending/base/updateCount/' + id + '/' + count,
    method: 'get',
  });
};

// 根据设备ID查询通道列表
export function getlistDevice(query: DeviceQuery) {
  return request({
    url: `/vending/base/listDevice`,
    method: 'get',
    params: query
  });
}

// 获取设备总数
export const getDeviceTotal = () => {
  return request({
    url: '/vending/base/total',
    method: 'get'
  });
};

// 获取在线设备数
export const getDeviceOnline = () => {
  return request({
    url: '/vending/base/online',
    method: 'get'
  });
};